/**
 * Created by c on 2017-12-04.
 */
//加载表格操作
function caozuo (){
    var cao = '<button class="layui-btn layui-btn-normal layui-btn-mini huifu">详情</button>' +
        '<button type="button"  class="layui-btn layui-btn-danger layui-btn-mini del">删除</button>';
    return cao;
}
var rows ;
window.optEvents= {
    "click .huifu": function (e,value,row) {
        $("div#context").children().remove();
        rows = row;
        $("div#liaotian").css({"display":"block"});
        $("div.modal").modal("show");
        var param = "mid="+row.mid;
        var woJunum = $("[name=woNum]").val();
        if(woJunum!="GH10001"){
            var par = "rid="+row.messageReceiver.rid;
            $.post(ctx+"/send/updateIsReader",par,function(){},"text");
        }
        $.ajax({
            url:ctx+"/send/huifu",
            dataType:"json",
            async:false,
            data:param,
            type:"POST",
            success:function(reply){
                $(reply).each(function(){
                    //转换时间
                    var time1=new Date(this.reDate);
                    var mouth = time1.getMonth()+1;
                    var day = time1.getDay();
                    var hour = time1.getHours();
                    var minutes = time1.getMinutes();

                    var _text = '';
                    if(hour>=6&&hour<9)
                        _text = '早上';
                    else if(hour>=9&&hour<11)
                        _text = '上午';
                    else if(hour>=11&&hour<13)
                        _text = '中午'
                    else if(hour>=13&&hour<17)
                        _text = '下午';
                    else
                        _text = '晚上';


                    var time = mouth+"月"+day+"日"+_text+hour+"点"+minutes+"分";

                    if(woJunum==this.worker.woJubnum){
                        $(' <p class="text-center">'+time+'</p>'+
                            '<div style="margin-top: 10px;margin-bottom: 10px; width: 100%; height: 59px; overflow: hidden;">'+
                            '<image class="img-circle pull-right" src='+ctx+'"/res/images/bg.jpg" style="width: 40px;height: 40px;"></image>'+
                            '<span class="pull-right" style="position: relative; top:10px; right:3px;">['+this.worker.role.department.deName+']&nbsp;'+this.worker.woName+'</span>'+
                            '<p  style="position: relative; top:36px; right:-90px;" class="pull-right">'+this.reContext+'</p>'+
                            '</div>').appendTo("div#context");
                    } else {
                        $('<p class="text-center">'+time+'</p>'+
                            '<div style="margin-top: 10px;margin-bottom: 10px;">'+
                            '<image class="img-circle" src='+ctx+'"/res/images/bg.jpg" style="width: 40px;height: 40px;"></image>'+
                            '<span>&nbsp;['+this.worker.role.department.deName+']&nbsp;'+this.worker.woName+'</span>'+
                            '<p style="margin-left: 40px;">'+this.reContext+'</p>'+
                            '</div>').appendTo("div#context");
                    }
                });
            }
        })
        // $.post(ctx+"/send/huifu",param,function(reply){
        //     var woJunum = $("[name=woNum]").val();
        //     $(reply).each(function(){
        //         //转换时间
        //         var time=new Date(this.reDate);
        //         var mouth = time.getMonth();
        //         var day = time.getDay();
        //         var hour = time.getHours();
        //         var minutes = time.getMinutes();
        //
        //         var _text = '';
        //         if(hour>=6&&hour<9)
        //             _text = '早上';
        //         else if(hour>=9&&hour<11)
        //             _text = '上午';
        //         else if(hour>=11&&hour<13)
        //             _text = '中午'
        //         else if(hour>=13&&hour<17)
        //             _text = '下午';
        //         else
        //             _text = '晚上';
        //
        //
        //         var time = mouth+"月"+day+"日"+_text+hour+"点"+minutes+"分";
        //
        //         if(woJunum==this.worker.woJubnum){
        //             $(' <p class="text-center">'+time+'</p>'+
        //                 '<div style="margin-top: 10px;margin-bottom: 10px; width: 100%; height: 59px; overflow: hidden;">'+
        //                 '<image class="img-circle pull-right" src='+ctx+'"/res/images/bg.jpg" style="width: 40px;height: 40px;"></image>'+
        //                 '<span class="pull-right" style="position: relative; top:10px; right:3px;">['+this.worker.role.department.deName+']&nbsp;'+this.worker.woName+'</span>'+
        //                 '<p  style="position: relative; top:36px; right:-90px;" class="pull-right">'+this.reContext+'</p>'+
        //                 '</div>').appendTo("div#context");
        //         } else {
        //             $('<p class="text-center">'+time+'</p>'+
        //                 '<div style="margin-top: 10px;margin-bottom: 10px;">'+
        //                 '<image class="img-circle" src='+ctx+'"/res/images/bg.jpg" style="width: 40px;height: 40px;"></image>'+
        //                 '<span>&nbsp;['+this.worker.role.department.deName+']&nbsp;'+this.worker.woName+'</span>'+
        //                 '<p style="margin-left: 40px;">'+this.reContext+'</p>'+
        //                 '</div>').appendTo("div#context");
        //         }
        //     });
        //     alert($('div#context').height())
        //     $('div#gun').animate({scrollTop:$('div#context').height()+'px'},500);
        // },"json");
    }
}

function fasong(){
    var content = $("textarea[name=reContext]").val();
    if(content==null || content==''){
        return;
    }
    var mid = rows.mid;
    var param = "reContext="+content+"&mid="+mid;
    $.post(ctx+"/send/addHuiFu",param,function(mess){
        console.log(mess)
        //转换时间
        var time=new Date(mess.reDate);
        var mouth = time.getMonth();
        var day = time.getDay();
        var hour = time.getHours();
        var minutes = time.getMinutes();

        var _text = '';
        if(hour>=6&&hour<9)
            _text = '早上';
        else if(hour>=9&&hour<11)
            _text = '上午';
        else if(hour>=11&&hour<13)
            _text = '中午'
        else if(hour>=13&&hour<17)
            _text = '下午';
        else
            _text = '晚上';


        var time = mouth+"月"+day+"日"+_text+hour+"点"+minutes+"分";


        $(' <p class="text-center">'+time+'</p>'+
            '<div style="margin-top: 10px;margin-bottom: 10px; width: 100%; height: 59px; overflow: hidden;">'+
            '<image class="img-circle pull-right" src='+ctx+'"/res/images/bg.jpg" style="width: 40px;height: 40px;"></image>'+
            '<span class="pull-right" style="position: relative; top:10px; right:3px;">['+mess.worker.role.department.deName+']&nbsp;'+mess.worker.woName+'</span>'+
            '<p  style="position: relative; top:36px; right:-90px;" class="pull-right">'+mess.reContext+'</p>'+
            '</div>').appendTo("div#context");
        $('div.gun').animate({scrollTop:$('div#context').height()+'px'},500);
        $("textarea[name=reContext]").val("");

    },"json");

}

function fmttitle(e,value,row){
    var woJunum = $("[name=woNum]").val();
    if(woJunum=="GH10001"){
        return '<p><i class="glyphicon glyphicon-folder-open"></i>&nbsp;&nbsp;&nbsp;&nbsp;<span>'+value.title+'</span></p>';
    } else if(value.messageReceiver.isReaded=="0"){
        return '<p><i class="glyphicon glyphicon-envelope"></i>&nbsp;&nbsp;&nbsp;&nbsp;<span>'+value.title+'</span></p>';
    } else if(value.messageReceiver.isReaded=="1") {
        return '<p><i class="glyphicon glyphicon-folder-open"></i>&nbsp;&nbsp;&nbsp;&nbsp;<span>'+value.title+'</span></p>';
    }
}

$(function(){
    $('.modal').on('hide.bs.modal', function () {
        search();
    })
})

function search(){
    var param={};
    param.title=$("input[name='title']").val();
    param.fasong=$("input[name='fasong']").val();
    param.jieshou=$("input[name='jieshou']").val();
    console.log(param)
    $("#drugTable").bootstrapTable("refresh",{query:param});
}
